stepper28 2.2.0
Loading...
Searching...
No Matches
stepper28.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef STEPPER28_H
29#define STEPPER28_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define STEPPER28_REG_INPUT_0 0x00
74#define STEPPER28_REG_INPUT_1 0x01
75#define STEPPER28_REG_OUTPUT_0 0x02
76#define STEPPER28_REG_OUTPUT_1 0x03
77#define STEPPER28_REG_POLARITY_0 0x04
78#define STEPPER28_REG_POLARITY_1 0x05
79#define STEPPER28_REG_CONFIG_0 0x06
80#define STEPPER28_REG_CONFIG_1 0x07
81 // stepper28_reg
83
88
93
98#define STEPPER28_P0_DMODE0_PIN 0x01
99#define STEPPER28_P0_DMODE1_PIN 0x02
100#define STEPPER28_P0_DMODE2_PIN 0x04
101#define STEPPER28_P0_DECAY1_PIN 0x08
102#define STEPPER28_P0_DECAY2_PIN 0x10
103#define STEPPER28_P0_TRQ0_PIN 0x20
104#define STEPPER28_P0_TRQ1_PIN 0x40
105#define STEPPER28_P0_SLEEP_X_PIN 0x80
106#define STEPPER28_P1_LO1_PIN 0x01
107#define STEPPER28_P1_LO2_PIN 0x02
108#define STEPPER28_P1_MO_PIN 0x04
109#define STEPPER28_P1_RST_PIN 0x08
110
115#define STEPPER28_P0_DEFAULT_CONFIG 0x00
116#define STEPPER28_P1_DEFAULT_CONFIG 0xF7
117
122#define STEPPER28_DIR_CW 1
123#define STEPPER28_DIR_CCW 0
124
129#define STEPPER28_PIN_LOW_LEVEL 0
130#define STEPPER28_PIN_HIGH_LEVEL 1
131
136#define STEPPER28_MODE_FULL_STEP 0x00
137#define STEPPER28_MODE_1_OVER_8 0x01
138#define STEPPER28_MODE_HALF_STEP_TYPE_B 0x02
139#define STEPPER28_MODE_1_OVER_32 0x03
140#define STEPPER28_MODE_HALF_STEP_TYPE_A 0x04
141#define STEPPER28_MODE_1_OVER_16 0x05
142#define STEPPER28_MODE_QUARTER_STEP 0x06
143#define STEPPER28_MODE_MASK 0x07
144
149#define STEPPER28_TORQUE_100_PCT 0x00
150#define STEPPER28_TORQUE_75_PCT 0x01
151#define STEPPER28_TORQUE_50_PCT 0x02
152#define STEPPER28_TORQUE_25_PCT 0x03
153#define STEPPER28_TORQUE_MASK 0x03
154
159#define STEPPER28_DECAY_MIXED 0x00
160#define STEPPER28_DECAY_SLOW 0x01
161#define STEPPER28_DECAY_FAST 0x02
162#define STEPPER28_DECAY_ADMD 0x03
163#define STEPPER28_DECAY_MASK 0x03
164
169#define STEPPER28_SPEED_VERY_SLOW 0
170#define STEPPER28_SPEED_SLOW 1
171#define STEPPER28_SPEED_MEDIUM 2
172#define STEPPER28_SPEED_FAST 3
173#define STEPPER28_SPEED_VERY_FAST 4
174
180#define STEPPER28_DEVICE_ADDRESS_A2A1A0_000 0x20
181#define STEPPER28_DEVICE_ADDRESS_A2A1A0_001 0x21
182#define STEPPER28_DEVICE_ADDRESS_A2A1A0_010 0x22
183#define STEPPER28_DEVICE_ADDRESS_A2A1A0_011 0x23
184#define STEPPER28_DEVICE_ADDRESS_A2A1A0_100 0x24
185#define STEPPER28_DEVICE_ADDRESS_A2A1A0_101 0x25
186#define STEPPER28_DEVICE_ADDRESS_A2A1A0_110 0x26
187#define STEPPER28_DEVICE_ADDRESS_A2A1A0_111 0x27
188 // stepper28_set
190
195
200
205#define STEPPER28_MAP_MIKROBUS( cfg, mikrobus ) \
206 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
207 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
208 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
209 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
210 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
211 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
212 // stepper28_map // stepper28
215
220typedef struct
221{
222 // Output pins
223 digital_out_t en;
224 digital_out_t dir;
225 digital_out_t clk;
226
227 // Input pins
228 digital_in_t int_pin;
229
230 // Modules
231 i2c_master_t i2c;
232
233 // I2C slave address
235
237
242typedef struct
243{
244 pin_name_t scl;
245 pin_name_t sda;
246
247 pin_name_t en;
248 pin_name_t dir;
249 pin_name_t clk;
250 pin_name_t int_pin;
251
252 uint32_t i2c_speed;
253 uint8_t i2c_address;
254
256
267
273
284
299
313
327err_t stepper28_write_register ( stepper28_t *ctx, uint8_t reg, uint8_t data_in );
328
341err_t stepper28_read_register ( stepper28_t *ctx, uint8_t reg, uint8_t *data_out );
342
354err_t stepper28_get_step_mode ( stepper28_t *ctx, uint8_t *mode );
355
367err_t stepper28_set_step_mode ( stepper28_t *ctx, uint8_t mode );
368
380err_t stepper28_get_torque ( stepper28_t *ctx, uint8_t *torque );
381
393err_t stepper28_set_torque ( stepper28_t *ctx, uint8_t torque );
394
406err_t stepper28_get_decay ( stepper28_t *ctx, uint8_t *decay );
407
419err_t stepper28_set_decay ( stepper28_t *ctx, uint8_t decay );
420
433err_t stepper28_get_sleep_x_pin ( stepper28_t *ctx, uint8_t *state );
434
447err_t stepper28_set_sleep_x_pin ( stepper28_t *ctx, uint8_t state );
448
461err_t stepper28_get_lo1_pin ( stepper28_t *ctx, uint8_t *state );
462
475err_t stepper28_get_lo2_pin ( stepper28_t *ctx, uint8_t *state );
476
489err_t stepper28_get_mo_pin ( stepper28_t *ctx, uint8_t *state );
490
503err_t stepper28_get_rst_pin ( stepper28_t *ctx, uint8_t *state );
504
517err_t stepper28_set_rst_pin ( stepper28_t *ctx, uint8_t state );
518
530
546void stepper28_drive_motor ( stepper28_t *ctx, uint32_t steps, uint8_t speed );
547
557
567
578void stepper28_set_direction ( stepper28_t *ctx, uint8_t dir );
579
589
599
610void stepper28_set_clk_pin ( stepper28_t *ctx, uint8_t state );
611
612#ifdef __cplusplus
613}
614#endif
615#endif // STEPPER28_H
616 // stepper28
618
619// ------------------------------------------------------------------------ END
err_t stepper28_get_decay(stepper28_t *ctx, uint8_t *decay)
Stepper 28 get decay function.
void stepper28_set_direction(stepper28_t *ctx, uint8_t dir)
Stepper 28 set direction function.
err_t stepper28_get_mo_pin(stepper28_t *ctx, uint8_t *state)
Stepper 28 get mo pin function.
void stepper28_cfg_setup(stepper28_cfg_t *cfg)
Stepper 28 configuration object setup function.
void stepper28_switch_direction(stepper28_t *ctx)
Stepper 28 switch direction function.
uint8_t stepper28_get_int_pin(stepper28_t *ctx)
Stepper 28 get int pin function.
err_t stepper28_read_register(stepper28_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 28 read register function.
err_t stepper28_set_rst_pin(stepper28_t *ctx, uint8_t state)
Stepper 28 set RST pin function.
err_t stepper28_default_cfg(stepper28_t *ctx)
Stepper 28 default configuration function.
err_t stepper28_set_sleep_x_pin(stepper28_t *ctx, uint8_t state)
Stepper 28 set sleep x pin function.
err_t stepper28_get_sleep_x_pin(stepper28_t *ctx, uint8_t *state)
Stepper 28 get sleep x pin function.
err_t stepper28_reset_device(stepper28_t *ctx)
Stepper 28 reset device function.
void stepper28_disable_device(stepper28_t *ctx)
Stepper 28 disable device function.
void stepper28_drive_motor(stepper28_t *ctx, uint32_t steps, uint8_t speed)
Stepper 28 driver motor function.
err_t stepper28_write_register(stepper28_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 28 write register function.
void stepper28_enable_device(stepper28_t *ctx)
Stepper 28 enable device function.
err_t stepper28_get_lo1_pin(stepper28_t *ctx, uint8_t *state)
Stepper 28 get lo1 pin function.
err_t stepper28_set_torque(stepper28_t *ctx, uint8_t torque)
Stepper 28 set torque function.
err_t stepper28_get_lo2_pin(stepper28_t *ctx, uint8_t *state)
Stepper 28 get lo2 pin function.
err_t stepper28_set_step_mode(stepper28_t *ctx, uint8_t mode)
Stepper 28 set step mode function.
err_t stepper28_set_decay(stepper28_t *ctx, uint8_t decay)
Stepper 28 set decay function.
err_t stepper28_get_rst_pin(stepper28_t *ctx, uint8_t *state)
Stepper 28 get RST pin function.
err_t stepper28_get_step_mode(stepper28_t *ctx, uint8_t *mode)
Stepper 28 get step mode function.
err_t stepper28_init(stepper28_t *ctx, stepper28_cfg_t *cfg)
Stepper 28 initialization function.
err_t stepper28_get_torque(stepper28_t *ctx, uint8_t *torque)
Stepper 28 get torque function.
void stepper28_set_clk_pin(stepper28_t *ctx, uint8_t state)
Stepper 28 set clk pin function.
stepper28_return_value_t
Stepper 28 Click return value data.
Definition stepper28.h:262
@ STEPPER28_ERROR
Definition stepper28.h:264
@ STEPPER28_OK
Definition stepper28.h:263
Stepper 28 Click configuration object.
Definition stepper28.h:243
pin_name_t clk
Definition stepper28.h:249
uint32_t i2c_speed
Definition stepper28.h:252
pin_name_t dir
Definition stepper28.h:248
pin_name_t scl
Definition stepper28.h:244
pin_name_t en
Definition stepper28.h:247
pin_name_t int_pin
Definition stepper28.h:250
pin_name_t sda
Definition stepper28.h:245
uint8_t i2c_address
Definition stepper28.h:253
Stepper 28 Click context object.
Definition stepper28.h:221
digital_in_t int_pin
Definition stepper28.h:228
i2c_master_t i2c
Definition stepper28.h:231
digital_out_t clk
Definition stepper28.h:225
digital_out_t en
Definition stepper28.h:223
uint8_t slave_address
Definition stepper28.h:234
digital_out_t dir
Definition stepper28.h:224